package com.aerozhonghuan.logisticsmall.framework.hybrid.actions;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.aerozhonghuan.logisticsmall.framework.hybrid.NewWebviewFragment;
import com.aerozhonghuan.logisticsmall.framework.hybrid.SimpleActionHandler;
import com.aerozhonghuan.logisticsmall.framework.hybrid.bean.JsMobileAgentConstants;
import com.aerozhonghuan.logisticsmall.framework.hybrid.bean.JsNotificationEvent;
import com.aerozhonghuan.foundation.eventbus.EventBusManager;
import com.aerozhonghuan.hybrid.XJsCallback;

import org.json.JSONObject;

/**
 * 描述
 * 作者 Zhang Yonghui
 * 创建日期 2019/1/21
 */
public class EventNotificationActionHandler extends SimpleActionHandler {
    private static final String KEY_EVENT = "event";
    private static final String KEY_DATA = "data";

    public EventNotificationActionHandler(NewWebviewFragment fragment) {
        super(JsMobileAgentConstants.FLAG_EVENTNOTIFICATION, fragment);
    }

    @Override
    public void handleAction(@NonNull String action, @Nullable JSONObject params, @Nullable XJsCallback callBack) {
        if (params == null) {
            return;
        }
        String event = params.optString(KEY_EVENT);
        String data = params.optString(KEY_DATA);
        EventBusManager.post(new JsNotificationEvent(event, data));
    }
}
